Skip to content

fix: comment retries, a stuck prefetch flag, a double feed fetch and compact errors, plus three behavior changes - #294

Merged
therealsama merged 1 commit into
mainfrom
fix/verified-retry-prefetch-and-restore-bugs
Nov 1, 2026
Merged

therealsama merged 1 commit into
mainfrom
fix/verified-retry-prefetch-and-restore-bugs

Conversation

@therealsama

@therealsama therealsama commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes four bugs, each reproduced by a test that fails on the unfixed code, and makes three behavior changes that are judgment calls.

Bug fixes

  • A story whose comments kept failing was replaced by "Failed to load item". The comments section's automatic retry called refresh(), which set the page-level error when the comments failed again. It now retries the comments only, with a new retryComments(), so the story stays.
  • Compact errors said "Something went wrong" instead of their message. A compact StateView showed its default title over a passed-in description, so "Failed to load comments" never showed (on main, the bug above replaced the story first). A passed-in description now takes the default title's place. The story lists' load-more error, which its test has pinned to "Something went wrong" since May, no longer passes its raw error, so it's unchanged.
  • A reconnect could leave background prefetching off until the page was reloaded. The reconnect retry aborted the request holding the priority-fetch registration, and nothing released it. The retry now releases it when it settles.
  • Opening a feed on a phone fetched its first page twice. The feed routes and /item/:id rendered different components, so the swipe viewer remounted when it moved the URL to its first story. They now render one component, MobileStoryRoute.

Behavior changes

  • Desktop Back from another feed restores the list instead of starting it over. Starting over was the design: reset() says "We're starting fresh, not restoring" (11d36b9), and 03dbe95's e2e test checks that Back drops the session. StoryList is now keyed by feed, so each feed restores its saved session, cursor included. A header tab still starts its feed over.
  • The desktop comment page keeps its comment when Algolia fails. It used to go to "Failed to load comment", as the "Error + Retry" e2e tests asserted. Now the comment from Firebase stays, and its replies show "Failed to load replies" with a Retry button. The page error is left for a comment with nothing to show.
  • The item cache is capped at 3 million characters, and other storage writes make room when storage is full. Chromium, Firefox and WebKit give an origin 5,242,880 characters of localStorage (measured in Playwright 1.63's builds, not on a real iPhone), and a typical cache is about 1.6 million. The feed lists, viewed times and theme now write through setLocalStorageItem(), which drops the older half of the cached items and tries once more when storage is full. Pruning no longer parses every cached thread.

Testing

  • Typecheck, lint and unit tests pass: 1125 tests, 30 new. 22 of the new tests fail with their change reverted (3 only because retryComments() is new); the other 8 cover behavior that has to stay.
  • E2e passes locally on Chromium, Mobile Safari and Mobile Chrome (673 passed, 32 skipped). Firefox 157 doesn't start on the machine this ran on, so Firefox is left to CI.
  • Existing tests changed: "Desktop Back between feeds" now expects the session to be kept, the two comment-detail "Error + Retry" tests expect the comment to stay, the MAX_CACHED_ITEMS test expects exactly 60 items (the old prune allowed 61), and the story list's in-list error test also checks the raw error isn't shown.

Known limitations

  • Back from another feed restores the list as of the last story click in it, which can be behind where the reader has scrolled since.
  • useInfiniteStories's reset() is no longer called by the app.
  • A thread over 1.5 million characters (about 3,900 comments) isn't cached.
  • MobileStoryRoute reads the saved swipe position only when it mounts, so one mounted on a feed route treats a later /item/:id without router state as a direct link. A reload mounts it fresh.

@therealsama
therealsama requested a review from kplachkov as a code owner October 6, 2026 15:39
@therealsama
therealsama force-pushed the fix/verified-retry-prefetch-and-restore-bugs branch from 5bb49f2 to fd98b6f Compare October 6, 2026 18:04
@therealsama therealsama changed the title fix: keep stories and comments on screen when Algolia fails, unstick background prefetching, and three smaller fixes fix: comment retries, a stuck prefetch flag and two feed bugs, plus a comment-page change and an item-cache cap Oct 6, 2026
@therealsama
therealsama force-pushed the fix/verified-retry-prefetch-and-restore-bugs branch 2 times, most recently from 5116bc4 to acbc2c3 Compare November 1, 2026 02:50
@therealsama therealsama changed the title fix: comment retries, a stuck prefetch flag and two feed bugs, plus a comment-page change and an item-cache cap fix: comment retries, a stuck prefetch flag, a double feed fetch and compact errors, plus three behavior changes Nov 1, 2026
…compact errors, plus three behavior changes

Four bug fixes and three behavior changes, each with its tests.

The comments section's automatic retry called refresh(), which refetches
the item and then its comments, and set the page-level error when the
comments failed again, so ItemDetail and FullScreenItem replaced a story
that had loaded with "Failed to load item". The section now retries the
comments only, with a new retryComments(), and keeps the comments error
set until each attempt settles. refresh() reports a comments failure
after the item loads as a comments error, so the page's Try Again shows
the story.

A reconnect retry aborted the request that had registered a priority
fetch and fetched again without one, so the count stayed up and
background prefetching stayed off until the page was reloaded. The
reconnect retry now releases the registration when it settles, whether
it succeeds, fails or is aborted, and a comment item releases it once
the item loads.

On a phone the feed routes and /item/:id rendered different components,
so the swipe viewer remounted when it moved the URL to its first story
and fetched the feed's first page again. They now render one component,
MobileStoryRoute, keyed by the times a feed route is entered from
another route.

A compact StateView showed its default title, "Something went wrong",
in place of a passed-in description, so the comments error's "Failed to
load comments" never showed. A passed-in description now takes the
default title's place. The story lists' load-more error no longer passes
its raw error, so it still reads "Something went wrong".

Desktop Back from another feed now restores the feed's saved list
instead of starting it over, as reset() had done since 03dbe95. The list
is keyed by feed, so it mounts for each one and restores its session,
cursor included. A header tab still starts its feed over.

The desktop comment page keeps a comment it got from Firebase when
Algolia fails. Its replies show their skeleton during the retries, then
"Failed to load replies" with a Retry button, instead of the page error,
which is left for a comment with nothing to show.

The item cache stays within 3 million of the 5,242,880 characters of
localStorage an origin gets, and doesn't keep a thread over half that.
The feed lists, viewed times and theme choice write through
setLocalStorageItem(), which drops the older half of the cached items
and tries once more when storage is full.
@therealsama
therealsama force-pushed the fix/verified-retry-prefetch-and-restore-bugs branch from acbc2c3 to 287bbe0 Compare November 1, 2026 03:11
@therealsama
therealsama enabled auto-merge November 1, 2026 18:54
@therealsama
therealsama merged commit 7e68cdd into main Nov 1, 2026
4 checks passed
@therealsama
therealsama deleted the fix/verified-retry-prefetch-and-restore-bugs branch November 1, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants